var contextPath = $("#mypreview").attr("name");
var fileName = null;
var filePathName = null;
$(function(){
	
	$('#imgB').uploadify({
		'uploader' : contextPath
				+ '/ipiinclude/ipiplugin/uploadify/scripts/uploadify.swf',
		'script' :  contextPath+"/upload_add.do",
		'cancelImg' : contextPath
				+ '/ipiinclude/ipiplugin/uploadify/cancel.png',
		'buttonImg' : contextPath
				+ '/ipiinclude/ipiplugin/uploadify/upload_pitcure.png',
		'sizeLimit' : 1024 * 1024 * 20,
		'multi' : false,
		'auto' : true,
		'fileExt' : '*.jpg;*.jpeg',
		'fileDesc' : 'Image Files (jpg,jpeg)',
		'queueID' : 'img_queueID',
		'queueSizeLimit' : 1,
		'simUploadLimit' : 1,
		'removeCompleted' : false,
		'onSelect' : function() {
		},
		'onComplete' : function(event, queueId, fileObj, response, data) {
			response = eval('(' + response + ')');
			if (response.result == 0) {
				$("#hid_imgB").val(response.path);
				$("#hid_img").val(response.pathIndex);
				$("#hid_imgS").val(response.pathOrder);
				filePathName = response.data[0];
				fileName = fileObj.name;
				$("#previewImg")[0].src =  filePathName + "?t=" + Math.random();
				$("#previewImg").show();

			} else {
				alert('图片上传失败！', 'warning');
				return;
			}
		},
		'onError' : function(event, ID, fileObj, errorObj) {
			if (errorObj.type === "File Size") {
				alert('超过图片上传大小限制（20M）！', 'warning');
				return;
			}
		},
		'onCancel' : function(event, ID, fileObj, errorObj) {
			$("#hid_imgB").val('');
			$("#previewImg").hide();
		}
	});
});

function toSubmit(){
	var yuan = $("#priceYuan").val();
	var fen = parseInt(yuan*100);
	$("#price").val(fen);
	alert(fen);
	$("#theForm").submit();
}
